﻿Imports DTO
Imports System.Windows.Forms
Imports System.Data.Linq

Public Class ThongSoDAO
    Public Function LayBang() As IQueryable(Of ThongSo)
        Dim dt As IQueryable(Of ThongSo)
        Dim db As New QuanLyNhaSachDataContext
        Dim qds = From p In db.ThongSos _
                 Select p
        dt = qds
        Return dt
    End Function

    Public Function QD1_SoLuongNhapMin() As Integer
        Dim db As New QuanLyNhaSachDataContext
        Dim qd = db.ThongSos.Single(Function(ts) ts.TenQD = "QD1_SoLuongNhapMin")
        Return qd.GiaTri
    End Function

    Public Function QD1_SoLuongTonMax() As Integer
        Dim db As New QuanLyNhaSachDataContext
        Dim qd = db.ThongSos.Single(Function(ts) ts.TenQD = "QD1_SoLuongTonMax")
        Return qd.GiaTri
    End Function

    Public Function QD2_SoLuongTonSauBanMin() As Integer
        Dim db As New QuanLyNhaSachDataContext
        Dim qd = db.ThongSos.Single(Function(ts) ts.TenQD = "QD2_SoLuongTonSauBanMin")
        Return qd.GiaTri
    End Function

    Public Function QD2_SoTienNoMax() As Integer
        Dim db As New QuanLyNhaSachDataContext
        Dim qd = db.ThongSos.Single(Function(ts) ts.TenQD = "QD2_SoTienNoMax")
        Return qd.GiaTri
    End Function

    Public Function QD4_SuDung_Hay_KhongSuDung() As Integer
        Dim db As New QuanLyNhaSachDataContext
        Dim qd = db.ThongSos.Single(Function(ts) ts.TenQD = "QD4")
        Return qd.GiaTri
    End Function

    Public Sub CapNhat(ByVal tsDTO As ThongSoDTO)
        Dim db As New QuanLyNhaSachDataContext
        'Dim qd = db.ThongSos.Single(Function(p) p.TenQD = tsDTO.TenQD)
        Dim qd = (From p In db.ThongSos _
                  Where p.TenQD = tsDTO.TenQD _
                  Select p).Single

        qd.GiaTri = tsDTO.GiaTri

        Try
            db.SubmitChanges()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End Try
    End Sub
End Class
